/*************************************************
Author: tony
Date: 03/12/2013
Description:
Notes:
*************************************************/

#ifndef __CMuseCfg_h__
#define __CMuseCfg_h__

#include "commclass.h"
#include "CTArray.h"
#include "CTHashObjectMgr.h"

class CMuseCfgData 
{
public:
    CMuseCfgData () : bHasConfig(false)
    {
        _ucLevel = 0;
        _LastTime = 0;
        _iExp = 0;
    }

    bool bHasConfig;
    unsigned char _ucLevel;
    int  _LastTime;
    int  _iExp;
};

class CMuseVipCfg
{
public:
    CMuseVipCfg () : bHasConfig(false)
    {
        _ucVipLv = 0;
        _ExtraTime = 0;
        _ExtraExp = 0;
    }

    bool bHasConfig;
    unsigned char _ucVipLv;
    int  _ExtraTime;
    int  _ExtraExp;
};

#define  MUSE_VIP_CONFIG_NUM  12
class CMuseCfg
{
public:

    CMuseCfg() 
    {
        _stMuseCfg.m_iUsedCount = MAX_ROLE_LEVEL + 1;
    }

    virtual ~CMuseCfg() 
    {
    }

    int AddConfig (CMuseCfgData & stMuseCfg)
    {
        if (stMuseCfg._ucLevel > MAX_ROLE_LEVEL || (0 != stMuseCfg._LastTime % MAX_MUSE_COUNT_TIME))
        {
            return ERROR_MUSE_CONFIG_INVALID;
        }

        if (_stMuseCfg[stMuseCfg._ucLevel].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_INVALID;
        }

        stMuseCfg.bHasConfig = true;
        _stMuseCfg[stMuseCfg._ucLevel] = stMuseCfg;
        return 0;
    }

    int GetMuseTime (short shLevel, int & iLastTime)
    {
        iLastTime = 0;
        if (!_stMuseCfg[shLevel].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_NONE;
        }

        iLastTime = _stMuseCfg[shLevel]._LastTime;
        return 0;
    }

    int GetMuseExp (short shLevel, int & iExp)
    {
        iExp = 0;
        if (!_stMuseCfg[shLevel].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_NONE;
        }

        iExp = _stMuseCfg[shLevel]._iExp;
        return 0;
    }

private:

    CTArray<CMuseCfgData, MAX_ROLE_LEVEL + 1> _stMuseCfg;

#if 0
    int AddConfig (CMuseVipCfg & stVipCfg)
    {
        if (stVipCfg._ucVipLv > MUSE_VIP_CONFIG_NUM || (0 != stVipCfg._ExtraTime % MAX_MUSE_COUNT_TIME))
        {
            return ERROR_MUSE_CONFIG_INVALID;
        }

        if (_stVipCfg[stVipCfg._ucVipLv].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_INVALID;
        }

        _stVipCfg[stVipCfg._ucVipLv] = stVipCfg;
        return 0;
    }

    int GetMuseTime (short shLevel, char chVipLv, int & iLastTime)
    {
        iLastTime = 0;
        if (!_stMuseCfg[shLevel].bHasConfig 
            || !_stVipCfg[chVipLv].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_NONE;
        }

        iLastTime = _stMuseCfg[shLevel]._LastTime + _stVipCfg[chVipLv]._ExtraTime;
        return 0;
    }

    int GetMuseExp (short shLevel, char chVipLv, int & iExp)
    {
        iExp = 0;
        if (!_stMuseCfg[shLevel].bHasConfig 
            || !_stVipCfg[chVipLv].bHasConfig)
        {
            return ERROR_MUSE_CONFIG_NONE;
        }

        iExp = _stMuseCfg[shLevel]._iExp + _stVipCfg[chVipLv]._ExtraExp;
        return 0;
    }

    CTArray<CMuseVipCfg, MUSE_VIP_CONFIG_NUM + 1> _stVipCfg;
#endif
};

#endif // __CMuseCfg_h__

